package com.xiaotao.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Slf4j
@Configuration
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        log.info("WebSocketConfig 已创建");
        return new ServerEndpointExporter();
    }
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry)
    {
        registry.addEndpoint("/ws")
                .setAllowedOrigins("*")
                .withSockJS();//
    }
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry)
    {
        // 客户订阅前缀
        registry.enableSimpleBroker(
                "/queue", "/topic");
        registry.setApplicationDestinationPrefixes("/app");
    }

}
